home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Mac OS Development Toolkit / Automation Essentials 2.3.0 / • Other Stuff / Scripting Aids / PointAndSee.vu < prev    next >
Encoding:
Text File  |  1998-03-19  |  6.5 KB  |  214 lines  |  [TEXT/MPS ]

  1. #########################################################################
  2. #    script             PointAndSee( )
  3. #########################################################################
  4. #    Description:    Point to something on the target, and when the mouse 
  5. #                    stops moving the script prints whatever VU sees there. 
  6. #                    For Control Panels in Control_Panel_List, there is an 
  7. #                    automatic -89 horizontal offset before comparing, if the
  8. #                    Control_Panel_Offset parameter is true.
  9. #    Version:        1.07
  10. #    Parameters:        see below
  11. #    Returns:        nothing
  12. #    History:
  13. #        08/25/93    SBR        Created
  14. #        09/08/94    SBR        added window_ordinality parameter
  15. #########################################################################
  16. Script PointAndSee
  17. (
  18.     window_ordinality := 1,
  19.     waitTime := 0,
  20.     moreDetail := 0,
  21.     print_new_window := true,
  22.     Control_Panel_Offset := false,
  23.     Control_Panel_List := {    'Date & Time','Easy Access','General Controls','Keyboard','Map',
  24.                             'Memory','Monitors','Mouse','Numbers','Sound'}
  25. )
  26. begin
  27.     global gActorName;
  28.     
  29.     tName := (match [target]).t;
  30.     if tName
  31.     begin
  32.         tName := "PointAndSee {tName}";
  33.         gActorName := tName;
  34.         actorName(gActorName);
  35.     end;
  36.     else begin
  37.         SysBeep();
  38.         println;     println;     println;     println;     println; 
  39.         println (*You Idiot!*) "You forgot to select a target!";
  40.         exit;
  41.     end;
  42.         
  43.     println "Point to something on the target, and when the mouse stops moving the script prints"; 
  44.     println "whatever VU sees there. For Control Panels in Control_Panel_List, there is an "; 
  45.     println "Note for VU 2.0.1 users ONLY: For Control Panels in the Control_Panel_List, there is an "; 
  46.     println "automatic -89 horizontal offset before comparing. Set the Control_Panel_Offset "; 
  47.     println "parameter to true to enable the offset. "; 
  48.  
  49.     previousDescriptor := [contentItem o:32766];
  50.     previousWindow := [window t:'12345 not a name'];        #bogus starting value
  51.     currentWindow := [window t:'54321 Paul Is Dead'];        #bogus starting value
  52.     
  53.     if not Control_Panel_Offset            # turn off the offset for all CPs
  54.         Control_Panel_List := {};
  55.         
  56.     while true
  57.     begin
  58.         mouseLocation := GetStoppedMousePosition( waitTime );
  59.         
  60.         currentWindow := match[window o:window_ordinality]!;
  61.         if currentWindow        # do nothing if there is not a window
  62.         begin
  63.             if previousWindow <> currentWindow
  64.             begin
  65.                 gActorName := "new window…";
  66.                 actorName(gActorName);
  67.  
  68.                 match [window o:window_ordinality k:?currentWindowItems];
  69.                 previousWindow := currentWindow;
  70.                 println;
  71.                 println currentWindow;
  72.                 if print_new_window
  73.                 begin
  74.                     for each kItem in currentWindow.k
  75.                         println kItem;
  76.                     println;
  77.                 end;
  78.                 
  79.                 if isMember(currentWindow.t, Control_Panel_List)
  80.                 begin
  81.                     cpOffset := -89;
  82.                     println "**** Using -89 horizontal offset for this Control Panel ****";
  83.                 end;
  84.                 else cpOffset := 0;
  85.  
  86.                 previousDescriptor := [contentItem o:32766];
  87.             end;
  88.             
  89.             if PointIsInRect( mouseLocation, currentWindow.r )
  90.             begin
  91.                 if gActorName <> "scanning…"
  92.                 begin
  93.                     gActorName := "scanning…";
  94.                     actorName(gActorName);
  95.                 end;
  96.                 
  97.                 for each currentWindowItem in currentWindowItems
  98.                 begin
  99.                     if PointIsInRect( mouseLocation, currentWindowItem.r, cpOffset ) and 
  100.                         currentWindowItem.o <> previousDescriptor.o
  101.                     begin
  102.                         previousDescriptor := currentWindowItem;
  103.                         
  104.                         if moreDetail
  105.                             println match currentWindowItem!;
  106.                         else println currentWindowItem;
  107.                             
  108.                         previousDescriptor := currentWindowItem;
  109.                     end;
  110.                 end;
  111.             end;
  112.             else if gActorName <> "out of window"
  113.             begin
  114.                 gActorName := "out of window";
  115.                 actorName(gActorName);
  116.             end;
  117.         end;
  118.     end;
  119. end;
  120.  
  121.  
  122. #########################################################################
  123. #    task             GetStoppedMousePosition( waitTime )
  124. #    Description:    Waits for the mouse to come to rest for more than 
  125. #                    waitTime seconds.
  126. #    Parameters:        waitTime    integer of seconds
  127. #    Returns:        The position the mouse stopped in.
  128. #    History:
  129. #        08/25/93    SBR        Created
  130. #        03/05/94    SBR        Modified for faster mouse checking
  131. #########################################################################
  132. task GetStoppedMousePosition( waitTime := 0 )
  133. begin
  134.     global gPreviousPosition, gActorName;
  135.     
  136.     if not gPreviousPosition                        # force mismatch first time through
  137.     begin
  138.         gPreviousPosition := {1,1};
  139.         currentPosition := {2,2};
  140.     end;
  141.     else currentPosition := (match [mouse]).p;
  142.     
  143.     while gPreviousPosition = currentPosition        # require some movement to start
  144.     begin
  145.         if gActorName <> "mouse is stopped" and gActorName <> "out of window"
  146.         begin
  147.             gActorName := "mouse is stopped";
  148.             actorName(gActorName);
  149.         end;
  150.  
  151.         currentPosition := (match [mouse]).p;
  152.     end;
  153.  
  154.     while gPreviousPosition <> currentPosition        # require ZERO movement to stop
  155.     begin
  156.         #if gActorName <> "mouse is moving…"
  157.         if gActorName <> "scanning…"
  158.         begin
  159.             #gActorName := "mouse is moving…";
  160.             gActorName := "scanning…";
  161.             actorName(gActorName);
  162.         end;
  163.  
  164.         gPreviousPosition := (match [mouse]).p;
  165.         
  166.         if waitTime = 0;                            # Adjust response time between actual
  167.         else if waitTime > 0                        # stop and detected stop. If waitTime
  168.             wait(waitTime);                            # is > 0, wait that # of seconds, if 
  169.         else if waitTime < 0                        # it is < 0, loop that # of times,
  170.             for i := -1 to waitTime step -1;        # which is less accurate but shorter.
  171.             
  172.         currentPosition := (match [mouse]).p;
  173.     end;
  174.  
  175.     return currentPosition;
  176. end;
  177.  
  178.  
  179. #########################################################################
  180. #    task             PointIsInRect( pointList, rectList, delta_h )
  181. #    Description:    Waits for the mouse to come to rest for more than 
  182. #                    waitTime seconds.
  183. #    Parameters:        pointList,        { x,y }            point where the mouse is
  184. #                    rectList,         { l,t,r,b }        item rect the mouse might be over
  185. #                    delta_h := 0    horizontal offset for System 7 control panels
  186. #    Returns:        True if the mouse is currently in the rectangle, else false
  187. #    History:
  188. #        08/25/93    SBR        Created
  189. #        03/02/94    SBR        Optimized for no delta_h.
  190. #########################################################################
  191. task PointIsInRect
  192.     pointList,        # { x,y }                        point where the mouse is
  193.     rectList,         # { left,top,right,bottom }        item rect the mouse might be over
  194.     delta_h := 0    # horizontal offset for System 7 control panels
  195. )
  196. begin
  197.     #println pointList;        # { x,y }
  198.     #println rectList;         # { left,top,right,bottom }
  199.     if not delta_h
  200.         return    (pointList[1] >= rectList[1]) and 
  201.                 (pointList[1] <= rectList[3]) and
  202.                 (pointList[2] >= rectList[2]) and
  203.                 (pointList[2] <= rectList[4]);
  204.     else return    (pointList[1] >= rectList[1] + delta_h) and 
  205.                 (pointList[1] <= rectList[3] + delta_h) and
  206.                 (pointList[2] >= rectList[2]) and
  207.                 (pointList[2] <= rectList[4]);
  208. end;
  209.  
  210.  
  211.  
  212.  
  213.